<template>
  <section class="page bg-white">
    <headerbar>{{title}}
      <broadcastDetail v-if="typeof detail.newsContent !='undefined' && tools.NotIsNull(detail.newsContent.ttsOssUrl)" :detail="detail"/>
    </headerbar>

    <section class="inner-content no-shadow">
      <section class="detail">
        <h1 class="title">{{preData.title}}</h1>
        <p class="date">来源：{{preData.source || '未知'}} <span class="float-right">时间：{{preData.createTime}}</span></p>
        <p class="color-red pdh-2 pdv-1 shortTitle">{{preData.shortTitle}}</p>
        <p class="line"></p>
        <div class="cont-text" v-saveImage v-if="detail.newsContentExt" v-html="detail.newsContentExt.contents">

        </div>
        <fileDownloadComponent :contentId="detail.newsContent.id"></fileDownloadComponent>
        <p class="pdv-2"></p>
        <viewsUpsComponent v-if="detail.newsContent"></viewsUpsComponent>
      </section>
    </section>
    <section class="d-scroll-2head bg-white " :class="[{'d-scroll-3head': isInputFocus}]">

      <commentListComponent v-if="detail.newsContent" :_contentId="detail.newsContent.id" :shareType="0" @onInputFocus="onInputFocus"></commentListComponent>
    </section>

    <readScore v-if="detail.newsContent" :_contentId="detail.newsContent.id" :type="1"></readScore>
  </section>
</template>

<script>
  import commentListComponent from '@/components/common/commentListComponent'
  import viewsUpsComponent from '@/components/common/viewsUpsComponent'
  import fileDownloadComponent from '@/components/common/fileDownloadComponent'
  export default {
    components: {viewsUpsComponent, commentListComponent,fileDownloadComponent},
    name: 'specialDetail',
    data () {
      return {
        preData: {},
        detail: {},
        title: '',
        isInputFocus: false,
      }
    },
    created () {
      this.preData = this.$store.state.specialDetail
      let flag = this.$route.query.flag
      if (flag === 1) {
        this.title = '活动'
      } else if (flag === 2) {
        this.title = '专题'
      } else {
        this.title = '党务知识'
      }
      this.$store.state.flagType = 1
      this.loadData()
    },
    methods: {
      onInputFocus(blo) {
        this.isInputFocus = blo;
      },
      loadData () {
        let id = this.$route.query.id
        // this.fetchService.contentPageDetail(id).then(res => {
        this.fetchService.contentDetailNew(id).then(res => {
          this.detail = res.data
          this.$store.state.newsDetail = this.detail.newsContent
          this.$store.state.newsDetail.detail = this.detail
          this.preData = this.detail.newsContent
          if (this.detail.newsContentExt) {
            this.historyAdd()
            this.updateCount()
          }
        })
      },
    // 添加到我的足迹
      historyAdd () {
        let data = {
          contentId: this.detail.newsContentExt.contentId,
          newsType: 0,  // 新闻类型(0图文;1长视频;2音频;3短视频)
        }
        this.fetchService.historyAdd(data).then((res) => {
        })
      },
      updateCount () {
        let params = {
          contentId: this.detail.newsContentExt.contentId,
          type: '1'
        }
        this.fetchService.updateCount(params).then(res => {
          if (res.code !== 0) {
            return false
          }
          this.preData.views ++
        })
      }
    }
  }
</script>

<style scoped>

</style>
